<template>
  <div>

    <router-link to="/edit">
      <img src="../assets/docx.jpg"  alt="word" class="image">
    </router-link>
  
    <div style="padding: 20px;">
      <span style="display: inline-block; white-space: nowrap; width: 100%; overflow: hidden; text-overflow:ellipsis;">{{garbageItem.name}}</span>
      <div class="bottom clearfix">
        <time class="time">time</time>
        <br>
        <br>
        <el-tooltip class="item" effect="dark" content="恢复" placement="bottom-start">
          <el-button type="success" icon="el-icon-refresh" circle @click="handleGarbage" size="mini"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start">
          <el-button type="danger" icon="el-icon-delete" circle @click="handleDelete" size="mini"></el-button>
        </el-tooltip>
      </div>
    </div>
  </div>
</template>

<script>
import {mapActions,mapState} from 'vuex'
import {reqDeleteArticle, reqLikeornotArticle, reqRecoverArticle,reqCompleteDeleteArticle} from '../api'
export default {
  name: 'GarbageArticle',
  props:{
    garbageItem:Object,
  },
  data:function (){
    return{
      currentDate: new Date(),
    }
  },
  computed:{
    ...mapState(['userInfo','likeList'])
  },
  mounted () {
//    this.recordGarbageList(this.userInfo.userid)
  },
  methods:{
    ...mapActions(['getLikeList','getGarbageList','getCreateList','getCurrentList','recordGarbageList','recordOnEdit']),
    //从垃圾箱恢复
    handleGarbage(){
      //调用恢复接口
      const result=reqRecoverArticle(this.garbageItem.id,this.userInfo.userid)

      console.log(result)
      setTimeout(() => {
        //更新回收站列表
        this.getGarbageList()
        //更新创建列表
        this.getCreateList()
        //更新收藏列表
        this.getLikeList()
        //更新浏览列表
      //  this.getCurrentList()
      },500)

    },
    //彻底删除
    handleDelete(){
      //调用彻底删除接口
      this.$alert('确定彻底删除该文档吗？', '彻底删除文档', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        
        //彻底删除 从回收站删除
        const result=reqCompleteDeleteArticle(this.garbageItem.id,this.userInfo.userid)
        setTimeout(() => {
          //更新回收站列表
          this.getGarbageList()
          //更新创建列表
          this.getCreateList()
          //更新收藏列表
          this.getLikeList()
          //更新浏览列表
          //this.getCurrentList()
        },500)

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    
  }
}
</script>

<style >
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
  margin-top: 8px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

</style>
